package util;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import datastructure.intdata.RandomListNode;

public class ComplexListConstructor {
	public static RandomListNode getList(int[] arr) {
		int n = arr.length;
		Random random = new Random();
		
		Map<Integer,RandomListNode> map = new HashMap<Integer, RandomListNode>();
		RandomListNode head = new RandomListNode(0);
		RandomListNode cur = head;
		for(int i = 1; i < n; i++) {
			RandomListNode tmp = new RandomListNode(i);
			cur.next = tmp;
			map.put(i, tmp);
			cur = cur.next;
		}
		
		cur = head;
		while(cur != null) {
			cur.random = map.get(random.nextInt(n));
			cur = cur.next;
		}
		
		return head;
	}
}
